package com.sds.sweng.swat.miplatform.service.figures.components;

import org.dom4j.Node;
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.LineBorder;

import com.sds.sweng.swat.miplatform.service.validation.ValidationInfo;
import com.sds.sweng.swat.miplatform.service.validation.ValidationProperties;
import com.sds.sweng.swat.miplatform.service.validation.ValidationProperty;
import com.sds.sweng.swat.miplatform.service.validation.ValidationType;

public class CheckboxComponent extends TextboxComponent {

	public CheckboxComponent(Node component, Node parent) {
		super(component, parent);
	}

	protected void initComponent() {
		super.initComponent();

		setText("     " + component.valueOf("@Text"));
		setBorder(null);
	}

	public ValidationProperty[] getValidationProperties(ValidationInfo validationInfo) {
		return new ValidationProperty[] {
			new ValidationProperty(ValidationProperties.COMPONENT_NAME , validationInfo.componentName),
			new ValidationProperty(ValidationProperties.ID, validationInfo.id),
			new ValidationProperty(ValidationProperties.BUSINESS_NAME, validationInfo.businessName),
			new ValidationProperty(ValidationProperties.TYPE, validationInfo.type),
			new ValidationProperty(ValidationProperties.REQUIRED, validationInfo.required),
			new ValidationProperty(ValidationProperties.REQUIRED_GROUP, validationInfo.requiredGroup)
		};
	}

	public String[] getValidationTypes() {
		return new String[] {
			ValidationType.NONE,
			ValidationType.CUSTOM
		};
	}

	protected void setBorderColor(String serviceId) {
		if (validationInfos.get(serviceId) == null) {
			setBorder(null);
			return;
		}

		if (validationInfos.get(serviceId).partied) {
			if (validationInfos.get(serviceId).required) {
				setBorder(new LineBorder(ColorConstants.red, 2));
			} else {
				setBorder(new LineBorder(ColorConstants.blue, 2));
			}
		} else {
			setBorder(null);
		}
	}

	protected void paintFigure(Graphics graphics) {
		super.paintFigure(graphics);

		int x = bounds.x;
		int y = bounds.y;

		graphics.drawRectangle(x+5, y+(bounds.height/2)-5, 10, 10);
	}

}
